#include <stdio.h>

int a[32][32],b[32][32];
int n;
int dx[]={0,1,-1,0,0};
int dy[]={0,0,0,1,-1};

void dfs(int p,int q)
{
    if (p>n+1||p<0||q>n+1||q<0||a[p][q]!=0)
    {
        return;
    }
    a[p][q]=1;
    for (int i=0;i<=4;i++)
    {
        dfs(p+dx[i],q+dy[i]);
    }
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=n;j++)
        {
            scanf("%d",&b[i][j]);
            if (b[i][j]==0)
            {
                a[i][j]=0;
            }
            else {a[i][j]=2;}
        }
    }
    dfs(0,0);
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=n;j++)
        {
            if (a[i][j]==0)
            {
                b[i][j]=2;
            }
            printf("%d ",b[i][j]);
        }
        printf("\n");
    }
    return 0;
}
